//
//  AppDelegate.m
//  OurJourney
//
//  Created by 李沛池 on 2017/3/31.
//  Copyright © 2017年 Godlike. All rights reserved.
//

#import "AppDelegate.h"
#import "LPCDefine.h"
//友盟点击统计
#import <UMMobClick/MobClick.h>
//百度crab
#import "CrabCrashReport.h"
#import "LPCSettingManager.h"
#import "GuideMovieViewController.h"

@interface AppDelegate ()<
CrashSignalCallBackDelegate>

@end

@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //打印沙盒路径
    NSLog(@"NSHomeDirectory = %@",NSHomeDirectory());
    
    //初始化
    [self initUI];
    
    //友盟统计
    [self configurationUM];
    
    //bug监测
    [self configurationCrabCrash];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


#pragma mark - Init
- (void)initUI
{
    //展示开屏引导页
    sleep(3);
    
    //关闭状态栏
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    
    //加载引导视频页
    [self initGuideMovieVC];
}

//加载引导视频页
- (void)initGuideMovieVC
{
//    BOOL isFirstLogin = [[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstLogin"] boolValue];
//    if (!isFirstLogin) {
        //是第一次
        GuideMovieViewController *wsCtrl = [[GuideMovieViewController alloc]init];
        wsCtrl.movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"cola1"ofType:@"mp4"]];
        self.window.rootViewController = wsCtrl;
        [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"isFirstLogin"];
//    }
}

//友盟统计
- (void)configurationUM
{
    UMConfigInstance.appKey = Umeng_Appkey;
    UMConfigInstance.channelId = @"LPC1314";
    [MobClick startWithConfigure:UMConfigInstance];
    [MobClick setCrashReportEnabled:NO];
}

//bug监测
- (void)configurationCrabCrash
{
    //Crash收集开关，默认打开
    [[CrabCrashReport sharedInstance] setCrashReportEnabled:YES];
    [[CrabCrashReport sharedInstance] setUploadCrashOnlyWifi:NO];
    [[CrabCrashReport sharedInstance] setStackSymbolsEnabled:YES];
    [[CrabCrashReport sharedInstance] setCrashCallBackDelegate:self];
    [[CrabCrashReport sharedInstance] initCrashReporterWithAppKey:CrashReporter_AppKey AndVersion:AppVersion AndChannel:@"LPC1314"];
}


#pragma mark - 百度bug统计
- (void)crashCallBack
{
    [[CrabCrashReport sharedInstance] setAppUsername:[LPCSettingManager sharedLPCSettingManager].userId];
    [[CrabCrashReport sharedInstance] addCrashAttachLog:[LPCSettingManager sharedLPCSettingManager].userId forKey:@"userId"];
}



@end
